* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for domestic market outcomes.

* Setup
* From Do File #P14
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_all_cvrnr_rauch.dta", clear
replace con_34 = "r" if con_34=="w"
gen shdiff = 1
replace shdiff = 0 if con_34=="r"
egen sumvrdA = sum(vrdA), by(cvrnrA aarA)
gen share = vrdA/sumvrdA
gen shdiff_wt = shdiff*share
collapse (mean) shdiff (sum) shdiff_wt, by(cvrnrA aarA)
tempfile temp1
save `temp1.dta', replace

* Main data
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\regression_data_domestic.dta", clear

merge 1:1 cvrnrA aarA using `temp1.dta', keep(match master) nogen

gen p = (p1==1 | p2==1 | p3==1)

xtset group aarA
gen Lshdiff = L.shdiff
gen L2shdiff = L2.shdiff
gen L3shdiff = L3.shdiff

gen Lshdiff_wt = L.shdiff_wt
gen L2shdiff_wt = L2.shdiff_wt
gen L3shdiff_wt = L3.shdiff_wt

gen shdiffy = shdiff if aar==aarA
gen shdiffy_wt = shdiff_wt if aar==aarA

egen mshdiffy = mean(shdiffy), by(cvrnrA)
gen diff = 1 if shdiff>0.5 & shdiff!=. & acquirer==0
replace diff = 0 if shdiff<=0.5 & acquirer==0
replace diff = 1 if mshdiffy>0.5 & shdiff!=. & acquirer==1 
replace diff = 0 if mshdiffy<=0.5 & acquirer==1 

egen mshdiffy_wt = mean(shdiffy_wt), by(cvrnrA)
gen diff_wt = 1 if shdiff_wt>0.5 & shdiff_wt!=. & acquirer==0
replace diff_wt = 0 if shdiff_wt<=0.5 & acquirer==0
replace diff_wt = 1 if mshdiffy_wt>0.5 & shdiff_wt!=. & acquirer==1 
replace diff_wt = 0 if mshdiffy_wt<=0.5 & acquirer==1 

foreach x in lnnprod {
areg `x' p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22 if minemployee_cvrnr>=10 & diff==1, absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA4.txt", keep(p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 

areg `x' p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22 if minemployee_cvrnr>=10 & diff==0, absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA4.txt", keep(p4 p3 p2 p1 test m1 m2 m3 m4 D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 

reg `x' p D_AA_1-D_AA_22 i.group_cvrnr if aar!=. & minemployee>=10 & diff==1, cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_A7.txt", keep(p D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes

reg `x' p D_AA_1-D_AA_22 i.group_cvrnr if aar!=. & minemployee>=10 & diff==0, cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_A7.txt", keep(p D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes
}